#include<bits/stdc++.h>
using namespace std;
struct node{
    int d,v,a;
};
node che[1000010];
int t,n,m,l,V,weizhi[1000010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++) cin>>che[i].d>>che[i].v>>che[i].a;
        for(int i=1;i<=m;i++) cin>>weizhi[i];
        sort(weizhi+1,weizhi+m+1);
        int cnt=0;
        for(int i=1;i<=n;i++) if(che[i].v>V&&che[i].d<=weizhi[m]) cnt+=1;
        int jianshu=1;
        if(cnt==0) jianshu=0;
        cout<<cnt<<" "<<m-jianshu<<endl;
    }
    return 0;
}
